package com.joysuch.wwyt.datasync.service;

import com.joysuch.wwyt.datasync.support.AopDataSyncDaoInterceptor;
import org.aopalliance.intercept.MethodInvocation;

public interface DataSyncCondition {

    /**
     * 解析需要拦截的信息。返回null将跳过本次判断
     * @param invocation
     * @return
     */
    AopDataSyncDaoInterceptor.Info extractSyncInfo(MethodInvocation invocation);

    /**
     * 查找服务名称
     * @param info
     * @param entity
     * @param id
     * @return
     */
   default String getServiceName(AopDataSyncDaoInterceptor.Info info, Object entity, Object id) {
       return DataSyncRegister.get(info.getDomainClass());
   }

   default boolean shouldSync(AopDataSyncDaoInterceptor.Info info) {
       info.setServiceName(DataSyncRegister.get(info.getDomainClass()));
       return info.getServiceName() != null;
   }
}
